package top.hcode.hoj.controller.oj;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.hcode.hoj.annotation.AnonApi;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.pojo.entity.user.Major;
import top.hcode.hoj.service.oj.MajorService;

import java.util.List;

@RestController
@RequestMapping("/api/oj/major")
public class MajorController {
    @Autowired
    private MajorService majorService;


    //注册的时候，当前端传来学院id的时候根据学院id查询专业
    @GetMapping("/depfandmajor")
    @AnonApi
    public CommonResult<List<Major>> getdeplist(@RequestParam(value = "oj", defaultValue = "ME") String oj,@RequestParam(value = "selectedId") String selectedId) {
        return majorService.depfandmajor(oj,selectedId);
    }

    // 此方法用于获取管理员后台页面的专业管理
    @GetMapping("/list_list")
    public CommonResult<List<Major>> getMajorlist() {
        return majorService.getLits();
    }
    @PostMapping("/addmajor")
    public CommonResult<Void> addmaojr(@RequestBody Major major) {
        return majorService.addmajor(major);
    }

    @PostMapping("/updatemajor")
    public CommonResult<Void> updatemajor(@RequestBody Major major) {
        return majorService.updatemajor(major);
    }

    @DeleteMapping("/deleteMajor")
    public CommonResult<Void> deleteMajor(@RequestBody Major major) {
        return majorService.deletemajor(major);
    }


}
